import axios from "axios"
const instance = axios.create({
    // baseURL:"http://520it.com:8881/cms"
    baseURL:'/api'
})
export default instance
//请求拦截器
instance.interceptors.request.use(function(config) {
    console.log("请求拦截器");
    // 请求头携带token
    let mytoken = localStorage.getItem("x-auth-token")
    if(mytoken){
        config.headers["x-auth-token"] = mytoken
    }
    return config;
}, error => {
    return Promise.reject(error)
});

//响应拦截器
instance.interceptors.response.use(function (response) {
    console.log("响应拦截器",response);
    // 统一在此处提示错误信息
    if(response.data.code !=0 && response.data.code !=400 && response.data.code !=407){
        alert(response.data.msg)
        return false
    }
    return response.data;
}, function (error) {
    return Promise.reject(error);
});
